package in.blogspot.khurram2java;


import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;
import android.content.Intent;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
import android.database.sqlite.SQLiteDatabase;//(sql)

public class AddShelve extends Activity  { 
	

	
	TextView tvStatus;
	TextView tvResult;

	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.addshelve);
		
		
		tvStatus = (TextView) findViewById(R.id.tvStatus);
		tvResult = (TextView) findViewById(R.id.tvResult);
		
		ImageButton scanBtn = (ImageButton) findViewById(R.id.btnScan);

		scanBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub

				try {
					
					Intent intent = new Intent(
							"com.google.zxing.client.android.SCAN");
					intent.putExtra("SCAN_MODE", "QR_CODE_MODE,PRODUCT_MODE");
					startActivityForResult(intent, 0);
				
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					Toast.makeText(getApplicationContext(), "ERROR:" + e, 1).show();

				}

			}
		});

		
		//myDBClass myDb = new myDBClass(this);//(sql)
		//myDb.getWritableDatabase(); // First method  (sql)
		
        }
	
	
	public void onActivityResult(int requestCode, int resultCode, Intent intent) {
		
		
		
		if (requestCode == 0) {

			if (resultCode == RESULT_OK) {
				
				
				tvStatus.setText(intent.getStringExtra("SCAN_RESULT_FORMAT"));
				tvResult.setText(intent.getStringExtra("SCAN_RESULT"));
				 
				String isbn = tvResult.getText().toString();
				
	            Intent regisadd = new Intent(AddShelve.this,RegisAdd.class);
	            regisadd.putExtra("isbn",isbn);
	    		startActivity(regisadd);


				
			} else if (resultCode == RESULT_CANCELED) {
				tvStatus.setText("Press a button to start a scan.");
				tvResult.setText("Scan cancelled.");
			}
		}
	}
	
}




